package com.ssy.lingxi.settle.accounts.controller;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.dto.request.PlatformCouponSettlementDetailExcelQueryRequestVO;
import com.ssy.lingxi.dto.request.PlatformCouponSettlementDetailQueryRequestVO;
import com.ssy.lingxi.dto.request.PlatformCouponSettlementQueryRequestVO;
import com.ssy.lingxi.dto.response.PlatformCouponSettlementDetailResponseVO;
import com.ssy.lingxi.dto.response.PlatformCouponSettlementResponseVO;
import com.ssy.lingxi.settle.accounts.model.bo.PayProveBO;
import com.ssy.lingxi.settle.accounts.model.vo.request.AllInPayVO;
import com.ssy.lingxi.settle.accounts.model.vo.request.ConfirmAccountCompleteVO;
import com.ssy.lingxi.settle.accounts.model.vo.request.ConfirmPayProve;
import com.ssy.lingxi.settle.accounts.model.vo.request.PayVO;
import com.ssy.lingxi.settle.accounts.service.IPlatformCouponSettlementService;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.time.LocalDateTime;
import java.util.List;

/**
 * @menu 结算能力 - 平台优惠券结算
 * @author 彭冬冬
 * @version 2.0.0
 * @date 2022/1/18 13:34
 */
@RestController
@RequestMapping("/settle/accounts/platform/coupon/settlement")
public class PlatformCouponSettlementController extends BaseController {


    @Resource
    private IPlatformCouponSettlementService service;

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-查询分页
     * @param request 请求
     * @param queryParameter 查询参数
     * @return 查询分页数据
     */
    @RequestMapping(value = "/pagePayableSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSettlementResponseVO>> pagePayableSettlement(HttpServletRequest request, @Valid PlatformCouponSettlementQueryRequestVO queryParameter) {
        return service.pagePayableSettlement(getSysUser(request), queryParameter);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-查询详情
     * @param request 请求
     * @param id 平台优惠券结算id
     * @return 平台结算优惠券信息
     */
    @RequestMapping(value = "/getPayableDetail", method = RequestMethod.GET)
    public Wrapper<PlatformCouponSettlementResponseVO> getPayableDetail(HttpServletRequest request, Long id) {
        getSysUser(request);
        return service.getInfo(id);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-查询明细分页
     * @param request 请求
     * @param queryParameter 查询条件
     * @return 平台结算优惠券明细项信息
     */
    @RequestMapping(value = "/pagePayableSettlementDetail", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSettlementDetailResponseVO>> pagePayableSettlementDetail(HttpServletRequest request, @Valid PlatformCouponSettlementDetailQueryRequestVO queryParameter) {
        return service.pagePayableSettlementDetail(getSysUser(request), queryParameter);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-查询明细导出
     * @param request 请求
     * @param response 响应
     * @param queryParameter 查询条件
     */
    @RequestMapping(value = "/payable/export", method = RequestMethod.GET)
    public void payableExport(HttpServletRequest request, HttpServletResponse response, @Valid PlatformCouponSettlementDetailExcelQueryRequestVO queryParameter) {
        service.payableExport(getSysUser(request), response, queryParameter);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-线上付款
     * @param request 请求
     * @param payVO 付款信息
     * @return 线上付款结果
     */
    @RequestMapping(value = "/pay", method = RequestMethod.POST)
    public Wrapper<Void> pay(HttpServletRequest request, @RequestBody @Valid PayVO payVO) {
        return service.pay(getSysUser(request),payVO);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-查看支付凭证
     * @param request 请求
     * @param id 平台优惠券结算id
     * @return 支付凭证
     */
    @RequestMapping(value = "/getPayablePayProve", method = RequestMethod.GET)
    public Wrapper<List<PayProveBO>> getPayablePayProve(HttpServletRequest request, Long id) {
        getSysUser(request);
        return service.findPayProves(id);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-通联支付付款
     * @param request 请求
     * @param payVO 付款信息
     * @return 通联支付付款结果
     */
    @RequestMapping(value = "all/in/pay", method = RequestMethod.POST)
    public Wrapper<Void> allInPay(HttpServletRequest request, @RequestBody @Valid AllInPayVO payVO) {
        return service.allInPay(getSysUser(request), payVO);
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-手动结算
     * @param httpRequest 请求
     * @param settlementVO 结算id
     * @return 手动结算结果
     */
    @RequestMapping(value = "/couponManualSettlement", method = RequestMethod.POST)
    public Wrapper<Void> couponManualSettlement(HttpServletRequest httpRequest, @RequestBody @Valid ConfirmAccountCompleteVO settlementVO) {
        return service.manualSettlement(getSysUser(httpRequest), settlementVO.getSettlementId());
    }

    /**
     * 平台后台-结算-平台结算-平台优惠券结算-平台结算
     * @return 结算结果
     */
    @RequestMapping(value = "/platformCouponSettlement", method = RequestMethod.GET)
    public Wrapper<Void> platformCouponSettlement() {
        return service.timingSettlement(LocalDateTime.now());
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-查询分页
     * @param request 请求
     * @param queryParameter 查询参数
     * @return 查询分页数据
     */
    @RequestMapping(value = "/pageReceivableSettlement", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSettlementResponseVO>> pageReceivableSettlement(HttpServletRequest request, @Valid PlatformCouponSettlementQueryRequestVO queryParameter) {
        return service.pageReceivableSettlement(getSysUser(request), queryParameter);
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-查询详情
     * @param request 请求
     * @param id 平台优惠券结算id
     * @return 平台优惠券结算数据
     */
    @RequestMapping(value = "/getReceivableDetail", method = RequestMethod.GET)
    public Wrapper<PlatformCouponSettlementResponseVO> getReceivableDetail(HttpServletRequest request, Long id) {
        getSysUser(request);
        return service.getInfo(id);
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-查询明细分页
     * @param request  请求
     * @param queryParameter 查询条件
     * @return 查询明细分页
     */
    @RequestMapping(value = "/pageReceivableSettlementDetail", method = RequestMethod.GET)
    public Wrapper<PageData<PlatformCouponSettlementDetailResponseVO>> pageReceivableSettlementDetail(HttpServletRequest request, @Valid PlatformCouponSettlementDetailQueryRequestVO queryParameter) {
        return service.pageReceivableSettlementDetail(getSysUser(request), queryParameter);
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-查询明细导出
     * @param request 令牌
     * @param response 响应
     * @param queryParameter 查询条件
     */
    @RequestMapping(value = "/receivable/export", method = RequestMethod.GET)
    public void receivableExport(HttpServletRequest request, HttpServletResponse response, @Valid PlatformCouponSettlementDetailExcelQueryRequestVO queryParameter) {
        service.receivableExport(getSysUser(request), response, queryParameter);
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-确认对账完成
     * @param request 请求
     * @param completeVO 确认信息
     * @return 确认结果
     */
    @RequestMapping(value = "/confirmAccountComplete",method = RequestMethod.POST)
    public Wrapper<Void> confirmAccountComplete(HttpServletRequest request,  @RequestBody @Valid ConfirmAccountCompleteVO completeVO)  {
        return service.confirmAccountComplete(getSysUser(request), completeVO);
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-确认付款凭证
     * @param request 请求
     * @param confirmVO 确认信息
     * @return confirmVO
     */
    @RequestMapping(value = "/confirmPayProve", method = RequestMethod.POST)
    public Wrapper<Void> confirmPayProve(HttpServletRequest request,  @RequestBody @Valid ConfirmPayProve confirmVO) {
        return service.confirmPayProve(getSysUser(request), confirmVO);
    }

    /**
     * 结算能力-平台结算管理-平台优惠券结算-查看支付凭证
     * @param request 请求
     * @param id 平台优惠券结算id
     * @return 支付凭证
     */
    @RequestMapping(value = "/getReceivablePayProve", method = RequestMethod.GET)
    public Wrapper<List<PayProveBO>> getReceivablePayProve (HttpServletRequest request, Long id) {
        getSysUser(request);
        return service.findPayProves(id);
    }
}
